/**
 * @param {string} s
 * @return {string}
 */
// 最长回文字符串
/*var longestPalindrome = function (s) {
  // 思路：从中间开始向两边扩散来判断回文串
  let palindrome = (s, l, r) => {
    while (l >= 0 && r < s.length && s[l] == s[r]) {
      // 向两边展开
      l--;
      r++;
    }
    // 返回以s[l]和s[r]为中心的最长回文串
    return s.substr(l + 1, r - l - 1);
  };
  let res = "";
  for (let i = 0; i < s.length; i++) {
    // 以s[i]为中心的最长回文串
    let s1 = palindrome(s, i, i);
    // 以s[i]和s[i+1]为中心的最长回文串
    let s2 = palindrome(s, i, i + 1);
    res = res.length > s1.length ? res : s1;
    res = res.length > s2.length ? res : s2;
  }
  return res;
  }*/
  var longestPalindrome = function(s) {
    let res=""
    for (let i = 0;i < s.length; i++){
        let l = i - 1, r = i+ 1;
        while (l >= 0 && r < s.length && s[l] == s[r]) r++,l--
        if (res.length < r - l - 1) res = s.substr(l + 1, r - l - 1)
        l = i, r = i + 1
        while(l >= 0&&r < s.length&&s[l] == s[r]) r++,l--
        if (res.length < r - l - 1) res = s.substr(l + 1, r - l - 1)
    }
    return res
};